Opened 13 years ago

Closed 12 years ago

Last modified 10 years ago

#1293 closed enhancement (fixed)

[raster] ST_Resize to resize raster tiles

Reported by: robe Owned by: dustymugs
Priority: medium Milestone: PostGIS 2.1.0
Component: raster Version: master
Keywords: history Cc:

Description (last modified by pracine)

Bborie,

I'm ticketing what we discussed. As mentioned, it would be nice to have a resize function that provides the similar functionality to gdal_translate that can take a percentage reduction or max pixel dimensions.

e.g.

what gdal_translate:

gdal_translate -of png -outsize 25% 25% original.png final.png
gdal_translate -of png -outsize 500 500 original.png final.png

Currently have to use ST_Resample for this which requires a lot more arguments, not to mention it doesn't seem to work for rasters with no srid information.

I'm envisioning the signature would look something like

ST_Resize(rast raster, width text, height text)

where width can be a numeric like '500' or can be a percentage like '50%' which is why I made it text.

This will make postgis raster useful for both GIS folks and non-GIS folks as having an easy function to resize a raster will speed up all kinds of analysis. Like I mentioned, my selfish need is that most of my raster projects do not involve objects that fit in a nice spatial reference landscape but the analysis functions we've got so far I'm finding very useful for those (e.g. image recognition, and just plotting and vectorizing non-GIS like things like anatomic parts, or construction objects)

Change History (17)

comment:1 by pracine, 13 years ago

what would be the difference with ST_Rescale()?

comment:2 by dustymugs, 13 years ago

ST_Resize would use the same underlying function calls as gdal_translate. ST_Rescale (ST_Resample) makes use the of the same underlying function call as gdalwarp. To use ST_Resample, the raster must have a SRID. I ran some basic tests on random pictures I had lying around (no spatial reference) using gdalwarp (to test for behavior) and as expected returned an error.

By the looks of it, gdal_translate will resize any image for you regardless of spatial reference.

So for one of my random pictures

gdal_translate -of png outsize 25% 25% 0884Parkfl\ copy.jpg TEST.PNG

gdal_translate works.

gdalwarp -ts 1000 1000 0884Parkfl\ copy.jpg test.tif

gdalwarp doesn't. Error given is:

ERROR 1: Unable to compute a transformation between pixel/line
and georeferenced coordinates for 0884Parkfl copy.jpg.
There is no affine transformation and no GCPs.

comment:3 by bnordgren, 13 years ago

This still seems like a valid tool request. The requirements would be:

# ignore the affine transform if there is no SRID # "adjust" the affine transform to correctly map pixel indices to geopoints after the pixels have been resized (if an SRID is present).

Does gdal_translate perform function #2 if given a georeferenced image? Perhaps it would point to a set of function calls which allow us a greater degree of control over the data type?

comment:4 by bnordgren, 13 years ago

Argh! I used redmine wiki formatting by mistake. Function #2 is the "adjusting" of the affine transform…

comment:5 by dustymugs, 13 years ago

Summary: ST_Resize to resize raster tiles[raster] ST_Resize to resize raster tiles

comment:6 by pracine, 13 years ago

Description: modified (diff)

comment:7 by pracine, 13 years ago

Milestone: PostGIS Raster FuturePostGIS Future

comment:8 by pracine, 12 years ago

That makes me say that all of the ST_resample(), ST_Rescale(), ST_ReSkew(), ST_SnapToGrid() should be based on the same underlying function as gdal_translate (and work even if they don't have a SRID) and only ST_Transform() should be based on the gdalwarp mechanic…

comment:9 by dustymugs, 12 years ago

No can do to using what underlies gdal_translate for those functions. The big drawback of gdal_translate (and underlying functionality) is that there is no ability to select a resampling algorithm. I'm assuming it uses nearest neighbor…

comment:10 by pracine, 12 years ago

to fix the unknow SRID issue, isn't it possible to assign a temporary dummy SRID (maybe not that dummy) to the raster before passing it to gdalwarp and to remove it once we get the result? Since the requested SRID and the dummy one would be the same there should not be side issue.

comment:11 by dustymugs, 12 years ago

That should work… would need significant testing though…

comment:12 by dustymugs, 12 years ago

Owner: changed from pracine to dustymugs
Status: newassigned

I just ran my go-to test raster through gdalwarp with a variety of SRSes (SRSs?) adjusting only the output pixel scale and the outputs from all are identical (including the raster's true SRS).

I'll go ahead and write this function so that others can start testing…

comment:13 by dustymugs, 12 years ago

Keywords: history added
Resolution: fixed
Status: assignedclosed

Added in r10774. Early Christmas gift for robe!

comment:14 by robe, 12 years ago

Thanks. Now I can create my christmas montage.

comment:15 by robe, 12 years ago

Works nicely even with out of db rasters: http://www.bostongis.com/blog/index.php?/archives/205-Waiting-for-PostGIS-2.1-ST_Resize-not-just-for-GIS.html

I promise to do something less playful and more work-related in the future :)

comment:16 by dustymugs, 12 years ago

Yay! Thanks for posting that it works.

comment:17 by robe, 10 years ago

Milestone: PostGIS FuturePostGIS 2.1.0

duh we never even marked this at 2.1.0

Note: See TracTickets for help on using tickets.